package com.heima.wemedia.listener;

import com.alibaba.fastjson.JSON;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.mapper.WmUserMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class KafkaListener {
    @Autowired
    private WmUserMapper wmUserMapper;
    @org.springframework.kafka.annotation.KafkaListener(topics = "createUser-topic")
    public void saveWmusers(String msg){
        if(!StringUtils.isEmpty(msg)){
            ApUser apUser = JSON.parseObject(msg, ApUser.class);
            WmUser wmUser = new WmUser();
            wmUser.setApUserId(apUser.getId());
            wmUser.setApAuthorId(apUser.getId());
            wmUser.setName(apUser.getName());
            wmUser.setPassword(apUser.getPassword());
            wmUser.setSalt(apUser.getSalt());
            wmUser.setImage(apUser.getImage());
            wmUser.setPhone(apUser.getPhone());
            wmUser.setStatus(9);
            wmUser.setEmail(apUser.getImage());
            wmUser.setType(0);
            wmUser.setCreatedTime(new Date());
            wmUserMapper.insert(wmUser);
        }
    }
}
